package com.normalsys.live.base.config;

import com.normalsys.live.base.redsession.DistributedLockAOP;
import com.normalsys.live.base.redsession.RedissonDistributedLock;
import com.normalsys.live.base.redsession.RedissonManager;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Project Name: yuntai
 * File Name: DistributedLockAutoConfiguration
 * Package Name: com.normalsys.manage.base.config
 * Date: 2018/7/17  9:36
 * Copyright (c) 2018, tianyul All Rights Reserved.
 */
@Configuration
public class DistributedLockAutoConfiguration {
    @Bean
    public RedissonManager redissonManagerBean(@Value("${redisson.address}") String address,
                                               @Value("${redisson.password}") String password,
                                               @Value("${redisson.connectionPoolSize}") int connectionPoolSize,
                                               @Value("${redisson.idleConnectionTimeout}") int idleConnectionTimeout,
                                               @Value("${redisson.connectTimeout}") int connectTimeout,
                                               @Value("${redisson.timeout}") int timeout,
                                               @Value("${redisson.pingTimeout}") int pingTimeout,
                                               @Value("${redisson.reconnectionTimeout}") int reconnectionTimeout) {
        return new RedissonManager(address, password, connectionPoolSize, idleConnectionTimeout, connectTimeout, timeout, pingTimeout, reconnectionTimeout);
    }

    @Bean
    public RedissonDistributedLock RedissonDistributedLockBean(RedissonManager redissonManager) {
        return new RedissonDistributedLock(redissonManager);
    }

    @Bean
    public DistributedLockAOP DistLockerAOPBean() {
        return new DistributedLockAOP();
    }
}
